package org.eclipse.epsilon.emc.rdbms.core.sqlstatement;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;

import org.eclipse.epsilon.emc.rdbms.core.persistancebroker.PersistanceBroker;
import org.eclipse.epsilon.emc.rdbms.core.persistancemechanism.RelationalDatabase;



public class SelectSQLStatement extends SQLStatement
{
	
	/** This is not implemented
	*/	
	@Override
	public String BuildForCriteria(ResultSet sqlTables, HashMap properties,
			HashMap<String, Object> props) {
		// TODO Auto-generated method stub
		return null;
	}

	/** This is not implemented
	*/	
	@Override
	public String BuildForCriteria(ResultSet sqlTables,
			HashMap<String, Object> props) throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	/** This method is to generate the SQL Statement to select an element from the database
	*@param tableInfo - The resultset containing the database,schema and table information
	*@param properties - This is the list of columns\attributes to be retrieved
	*@param criteria - This is the hashmap of attributes and values that will be specified in the where clause.
	*@return statement - This is the generated SQL Statement to delete the object from the database
	*/	
	@Override
	public String BuildForCriteria(ResultSet tableInfo,ArrayList<String> properties, HashMap<String, Object> criteria) throws SQLException {
		RelationalDatabase connection = PersistanceBroker.connectTo();
		String  statement = "";

	    	 while (tableInfo.next())
	 		 {
	 			databaseName = tableInfo.getString("TABLE_CAT");
	 			schemaName = tableInfo.getString("TABLE_SCHEMA");
	 			tableName = tableInfo.getString("TABLE_NAME");	
	 		 }
	    	statement = connection.getClauseStringSelect();				
	 		statement = statement + getStringFromArrayList(properties,new ArrayList<String>());  //This list the name of the columns to be inserted with data.
	 		statement = statement + connection.getClauseStringFrom() +databaseName+"."+schemaName+"."+tableName;  //This list the name of the columns to be inserted with data.	 			 		
	    	if(criteria !=null && criteria.size() > 0) {statement = statement +connection.getClauseStringWhere()+getStringFromHashMap(criteria,"and");}	 	 		
	    	return statement;
	}


	/** This is not implemented
	*/	
	@Override
	public String BuildForCriteria(ResultSet tableInfo, ResultSet sqlColumns,
			ResultSet primaryKey, ResultSet columnMetaData,
			HashMap<String, Object> properties) throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	/** This is not implemented
	*/
	@Override
	public String BuildForCriteria(ResultSet sqlTables,
			ArrayList<String> columns, ArrayList PKtables, ArrayList FKtables,
			ArrayList PKcols, ArrayList FKcols,
			HashMap<String, Object> parameters) throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}



	
}
